package com.ehotting.mqbd.zw.api.domain.netty.job;


import com.ehotting.eaf.core.utils.ByteUtils;
import com.ehotting.mqbd.zw.api.constants.ActionConstants;
import com.ehotting.mqbd.zw.api.domain.netty.ZwCommPacket;
import com.ehotting.mqbd.zw.api.domain.protoc.ZwJobStreamOuterClass;
import com.google.protobuf.InvalidProtocolBufferException;

public class JobCommitReq extends ZwCommPacket {

    private ZwJobStreamOuterClass.ZwTaskStream zwTaskStream;
    private ZwJobStreamOuterClass.JobOption jobOption;
    private ZwJobStreamOuterClass.ZwJobStream zwJobStream;

    public JobCommitReq() {
        super(ActionConstants.Cmd_FileSendStr);
    }

    public ZwJobStreamOuterClass.ZwTaskStream getZwTaskStream() {
        return zwTaskStream;
    }

    public void setZwTaskStream(ZwJobStreamOuterClass.ZwTaskStream zwTaskStream) {
        this.zwTaskStream = zwTaskStream;
    }

    public ZwJobStreamOuterClass.JobOption getJobOption() {
        return jobOption;
    }

    public void setJobOption(ZwJobStreamOuterClass.JobOption jobOption) {
        this.jobOption = jobOption;
    }

    public ZwJobStreamOuterClass.ZwJobStream getZwJobStream() {
        return zwJobStream;
    }

    public void setZwJobStream(ZwJobStreamOuterClass.ZwJobStream zwJobStream) {
        this.zwJobStream = zwJobStream;
    }

    @Override
    public void convertToHexStr() {
        if (zwTaskStream!=null && jobOption!=null && zwJobStream!=null) {
            byte[] zwTaskStreamBuff = zwTaskStream.toByteArray();
            byte[] jobOptionBuff = jobOption.toByteArray();
            byte[] zwJobStreamBuff = zwJobStream.toByteArray();
            byte[] buff = ByteUtils.byteMerger(zwTaskStreamBuff, jobOptionBuff, zwJobStreamBuff);
            this.setBuff(buff);
        }
    }

    @Override
    public void convertToProp() {
        byte[] buff = this.getBuff();
        int bufSize = this.getHead().getBufSize();
        if (buff==null||bufSize==0){
            return;
        }
        try {
            this.zwTaskStream = ZwJobStreamOuterClass.ZwTaskStream.parseFrom(buff);
            this.jobOption = ZwJobStreamOuterClass.JobOption.parseFrom(buff);
            this.zwJobStream = ZwJobStreamOuterClass.ZwJobStream.parseFrom(buff);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        JobCommitReq req = new JobCommitReq();
        System.out.println(req.toString());
        System.out.println(req.getZwTaskStream().getId());

    }
}
